package nz.co.doherty.gwtpbreadcrumbs.client.ui.app;

import nz.co.doherty.gwtpbreadcrumbs.client.i8n.ClientConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.philbeaudoin.gwtp.mvp.client.ViewImpl;

public class AppViewImpl extends ViewImpl implements AppView {

	interface Binder extends UiBinder<Widget, AppViewImpl> {
	}

	protected static final Binder binder = GWT.create(Binder.class);

	private final Widget widget;

	@UiField
	SimplePanel topBarContainer;

	@UiField
	SimplePanel mainContentContainer;

	private ClientConstants constants;

	@Inject
	public AppViewImpl(ClientConstants constants) {
		this.constants = constants;
		widget = binder.createAndBindUi(this);

	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	@Override
	public void setContent(Object slot, Widget content) {
		if (slot == AppPresenter.TYPE_RevealMainContent) {
			setMainContent(content);
		} else if (slot == AppPresenter.TYPE_RevealTopBarContent) {
			setTopBarContent(content);
		} else {
			super.setContent(slot, content);
		}
	}

	private void setMainContent(Widget mainContent) {
		this.mainContentContainer.clear();
		if (mainContent != null)
			this.mainContentContainer.add(mainContent);
	}

	private void setTopBarContent(Widget topContent) {
		this.topBarContainer.clear();
		if (topContent != null) {
			this.topBarContainer.add(topContent);
		}
	}
}
